package com.deke.home.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.deke.entity.TbArticle;
import com.deke.home.dao.ArticleManagementDao;
import com.deke.home.service.ArticleManagementService;
import com.deke.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author ：ludi（206913808@qq.com）
 * @date ：Created in 2022/12/17 15:47
 * @description：
 * @modified By：
 * @version:
 */
@Service
public class ArticleManagementServiceImpl implements ArticleManagementService {

    @Autowired
    private ArticleManagementDao articleManagementDao;

    /**
     * @create by: ludi（206913808@qq.com）
     * @description: 查询
     * @create time: 2022/12/17 15:48
     * @return com.deke.vo.Result
     */
    @Override
    public Result getArticleByNavId(Map map) {
        QueryWrapper<TbArticle> wrapper = new QueryWrapper<>();
        wrapper.eq("nav_id", map.get("navId"));
        TbArticle tbArticle = articleManagementDao.selectOne(wrapper);
        return new Result(2000, "查询成功",tbArticle);
    }


    /**
     * @create by: ludi（206913808@qq.com）
     * @description: 修改文章(名称、描述)
     * @create time: 2022/12/17 16:15
     * @param tbArticle
     * @return com.deke.vo.Result
     */
    @Override
    public Result updateArticleByNavId(TbArticle tbArticle) {
        UpdateWrapper<TbArticle> wrapper = new UpdateWrapper<>();
        wrapper.eq("nav_id", tbArticle.getNavId());
        tbArticle.setArtDesc(tbArticle.getArtDesc());
        tbArticle.setArtTitle(tbArticle.getArtTitle());
        articleManagementDao.update(tbArticle, wrapper);
        return new Result(2000, "修改成功");
    }
}